/*
 * Powered By XY
 * Since 2020
 */

package com.xy.biz.auth.service.impl;

import com.xy.biz.auth.domain.bo.UserLogStatusBO;
import com.xy.biz.auth.domain.query.UserLogStatusQuery;
import com.xy.biz.auth.manager.UserLogStatusManager;
import com.xy.biz.auth.service.UserLogStatusService;
import com.xy.lang.domain.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 
 * 
 * @author zsp
 * @date 2020-8-20
 */
@Service
public class UserLogStatusServiceImpl implements UserLogStatusService {

	@Autowired
	private UserLogStatusManager userLogStatusManager;
	
	@Override
	public Result<?> updateUserLogStatus(UserLogStatusBO userLogStatusBO) {
		int affectedRows = userLogStatusManager.updateUserLogStatus(userLogStatusBO);
		if (affectedRows == 0) {
			try {
				userLogStatusManager.saveUserLogStatus(userLogStatusBO);
			} catch (DuplicateKeyException e) {
				affectedRows = userLogStatusManager.updateUserLogStatus(userLogStatusBO);
			}
		}
		if (affectedRows > 0) {
			return Result.success();
		}
		return Result.ofErrorRowsAffected();
	}
	
	@Override
	public List<UserLogStatusBO> listUserLogStatus(UserLogStatusQuery query) {
		return userLogStatusManager.listUserLogStatus(query);
	}
	
	@Override
	public int countUserLogStatus(UserLogStatusQuery query) {
		return userLogStatusManager.countUserLogStatus(query);
	}
	
}
